package com.springBoot.controller;

import com.springBoot.service.ExcelService;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.OutputStream;

@RestController
public class SysDeptController {
    @Autowired
    private ExcelService excelService;
    @GetMapping("/getExcel")
    public void getExcel(HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment; filename=sysDept.xlsx");
        Workbook excel = excelService.getExcel();

        OutputStream outputStream = response.getOutputStream();
        excel.write(outputStream);
        outputStream.close();

        excel.close();
    }
}
